program define mcprobit, eclass
version 15.0
syntax varlist [if] [in] [,			///
		MC(string) FROM(string) ///
		DIFF NOLOG ITERate(int 300) ///
		VCE(passthru) ///
		TECHnique(passthru) ///
		* ///
		]
		
marksample touse
gettoken depvar indeps:varlist

local vceopt =	`:length local vce'		|	///
		`:length local weight'		|	///
		`:length local cluster'		|	///
		`:length local robust'
if `vceopt' {
	_vce_parse, argopt(CLuster) opt(OIM OPG Robust) old	///
		: [`weight'`exp'], `vce' `robust' `cluster'
	local vce
	if "`r(cluster)'" != "" {
		local clustvar `r(cluster)'
		local vce vce(cluster `r(cluster)')
	}
	else if "`r(robust)'" != "" {
		local vce vce(robust)
	}
	else if "`r(vce)'" != "" {
		local vce vce(`r(vce)')
	}
}

ml model lf mcprobit_lf (`depvar': `depvar' = `indeps') (a0: `mc') (a1: `mc') if `touse', ///
	max init(`from') `diff' `nolog' iterate(`iterate') `vce'


tempname b v ll chi2
matrix `b' = e(b)
matrix `v' = e(V)
local converged = e(converged)
local N = e(N)
scalar `ll' = e(ll)
ereturn post `b' `v', esample(`touse')
qui test `indeps'
scalar `chi2' = r(chi2)
local df_m = r(df)
ereturn scalar ll = `ll'
ereturn scalar N = `N'
ereturn scalar chi2 = `chi2'
ereturn scalar df_m = `df_m'
ereturn scalar converged = `converged'
ereturn local cmd mcprobit
ereturn local predict mcprobit_p

_prefix_display
end
exit

